using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Torch : MonoBehaviour
{
    public static event System.Action<Torch> Lit;

    public bool IsLit { get; private set; }

    [SerializeField]
    private Cable _cable;

    [SerializeField]
    private Animator _animator;

    [SerializeField]
    private ParticleSystem[] _effects;

    [SerializeField]
    private AudioClip _sound;


    private void Awake()
    {
        SetLit(false);
    }

    private void OnEnable()
    {
        _cable.Lit += Cable_Lit;
    }

    private void OnDisable()
    {
        _cable.Lit -= Cable_Lit;
    }

    public void SetLit(bool lit)
    {
        IsLit = lit;
        _animator.SetBool("Active", lit);
    }

    private void Cable_Lit()
    {
        SetLit(true);

        AudioPlayer.Instance.PlaySound(_sound);
        foreach (var fx in _effects)
        {
            fx.Play();
        }
        Lit?.Invoke(this);
    }
}
